package top.xia17.plugins.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import top.xia17.plugins.fast.common.security.auditor.JpaSecurityAuditorAware;

import java.util.Optional;

/**
 * @author xia17
 * @since 2022/2/23 11:31
 */
@Configuration
public class JpaConfiguration {


    @Bean(name = "auditorAware")
    public AuditorAware<String> auditorAware(){
        return new MyJpaSecurityAuditorAware();
    }



    static class MyJpaSecurityAuditorAware extends JpaSecurityAuditorAware {
        @Override
        public Optional<String> getCurrentAuditor() {
            try {
                return super.getCurrentAuditor();
            }catch (RuntimeException e){
                return Optional.of("system");
            }
        }
    }


}
